/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package callProcs;

/**
 *
 * @author josema
 */
import java.math.BigInteger;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;


public class ProcsUsuario {
    
   java.sql.Connection  con = null;
    public ProcsUsuario(){
        try {
            con = DriverManager.getConnection("jdbc:mysql://localhost:3306/bufete","root","");
            
        } catch (SQLException ex) {
            Logger.getLogger(ProcsInsertar.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public java.sql.ResultSet VerTiposUsuario() throws SQLException{
         java.sql.ResultSet rs = null ;
       
            Statement cs = con.createStatement();   
            rs = cs.executeQuery("SELECT Nombre_de_Nivel from Nivel_de_Usuario");
           return rs;
     }
    
     public java.sql.ResultSet verModulos_NivelUsuario(String sentencia) throws SQLException{
         java.sql.ResultSet rs = null ;
       System.out.println(sentencia);
            Statement cs = con.createStatement();
            rs = cs.executeQuery("SELECT NU.Nombre_de_Nivel, PR.Modulo from Nivel_de_Usuario NU "
                                + "inner join Nivel_de_Usuario_has_Privilegios NP ON NP.Nivel_de_Usuario_Nombre_de_Nivel=NU.Nombre_de_Nivel "
                    + "inner join Privilegios PR ON PR.Modulo=NP.Privilegios_Modulo " 
                                 +"WHERE NU.Nombre_de_Nivel = '" + sentencia + "'");
           
     
        return rs;
     }
    
    
   public void InsertaTipoUser(String NtipoUser) throws SQLException{
        
          java.sql.CallableStatement cs = con.prepareCall("{call InsertaTipoUsuario('" + NtipoUser + "' )}");
    
           java.sql.Statement stmt  = con.createStatement();
           java.sql.ResultSet rs = cs.executeQuery();
        
    }
   
   public void InsertaModulosTipoUser(String NtipoUser, String Modulo) throws SQLException{
        
          java.sql.CallableStatement cs = con.prepareCall("{call InsertarModulosaTipodeUsuario('" + NtipoUser + "','"+Modulo+ "' )}");
    
           java.sql.Statement stmt  = con.createStatement();
           java.sql.ResultSet rs = cs.executeQuery();
        
    }
    
   public java.sql.ResultSet VerificaModulos(String NtipoUser, String Modulo) throws SQLException{
         java.sql.ResultSet rs = null ;
       
            Statement cs = con.createStatement();   
            
            rs = cs.executeQuery("SELECT count(Privilegios_Modulo) "
                                +"from Nivel_de_Usuario_has_Privilegios "
                                 +"WHERE Nivel_de_Usuario_Nombre_de_Nivel = '" + NtipoUser + "'"
                    + " and Privilegios_Modulo = '" + Modulo + "'");
            
           return rs;
     }
    
    public void EliminarModulosTipoUser(String NtipoUser, String Modulo) throws SQLException{
        
          java.sql.CallableStatement cs = con.prepareCall("{call eliminarModulos('" + NtipoUser + "','"+Modulo+ "' )}");
    
           java.sql.Statement stmt  = con.createStatement();
           java.sql.ResultSet rs = cs.executeQuery();
        
    }
}
